﻿
@{
    Layout = null;
}

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="/layui/css/layui.css">
    <script src="/jquery.min.js"></script>
    <script src="/jquery.cookie.js"></script>
    <script src="/layui/layui.js"></script>
    <script src="/_js/framework_layui.js?time=@DateTime.Now.Ticks"></script>
    <link rel="stylesheet" href="~/sitecss/logincss.css">
    <title>WTM</title>
    <script type="text/javascript">
        $(document).ready(function () {
        //利用access_token获取openid，如果成功则调用后台AutoLogin方法，完成登录。
        $.ajax({
            url: 'https://api.github.com/user?' + '@ViewBag.acc',
            success: function (res) {
                var openid = res.login;
                autoLogin(openid);
            },
            error: function (xhr) {
                myFunction();
            },

        })
        });
        //发生错误弹出窗口
        function myFunction() {
            if (confirm("网络错误，稍后重试")) {
                window.location.href = "/Login/Login"
            } else {
                window.location.href = "/Login/Login"
            }
        }
        //调用后台AutoLogin
        function autoLogin(id) {
            $.ajax({
            url: '/api/AuthenticationApi/AutoLogin?openid='+id,
            type: 'post',
                success: function (res) {
                    console.log(res)

                if (res.access_token == 'no') {
                    window.location.href = '/Login/Reg';
                } else {
                    window.location.href = "/"
                }
            },
            error: function (xhr) {
                myFunction();
            },

        })
        };
    layui.use('layer');
    </script>
</head>

<body class="loginBody">
    <div class="loginDiv">
        <h4>
            登录中...
        </h4>

    </div>


</body>

</html>
